import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Network {
  List<Node> my_nodes;
  List<Edge> my_edges;
  List<Edge> my_forward_edges;
  List<Edge> my_backward_edges;
  Node my_s;
  Node my_t;

  public Network(final List<Node> the_nodes, final List<Edge> the_edges) {
    my_nodes = the_nodes;
    my_edges = the_edges;
  }
  
  public Network(final List<Node> the_nodes, final List<Edge> the_forward_edges, final List<Edge> the_backward_edges) {
    my_nodes = the_nodes;
    my_forward_edges = the_forward_edges;
    my_backward_edges = the_backward_edges;
  }
  
  public Map<Integer,Edge> getEdgeByChannels(){
	 Map<Integer,Edge> map = new HashMap<>();
	 for(Edge e: my_edges){
		 Edge n = map.get(e.my_channel);
		if((n == null ||n.my_v.my_demand - n.my_v.throughput < e.my_v.my_demand-e.my_v.throughput) & e.my_u.isTransmiting & !e.my_v.isTransmiting){
			map.put(e.my_channel, e);
		}
	 }
	 return map;
  }

  public double getTotalThroughput(){
	  double th = 0;
	  for(Node n : my_nodes){
		  th = n.throughput+th;
	  }
	  return th;
  }
  
  public void reset(){
	  for(Node n : my_nodes){
		  n.throughput = 0;
		  n.received = 0;
		  n.discovered = false;
		  n.explored = false;
		  n.isTransmiting = false;
		  n.my_in.clear();
		  n.my_out .clear();
	  }
  }
}
